package com.kingstar.ceres.constants;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kingstar.ceres.entity.master.*;
import com.kingstar.ceres.mapper.master.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * TODO
 *
 * @Author chen.dai
 * @Date 2021/1/9 17:42
 * @Memo
 **/

@Getter
@AllArgsConstructor
public enum DbEntityEnum {

    CFETS_CMDS_STANDARD_RATE(CfetsCmdsStandardRate.class, CfetsCmdsStandardRateDao.class,new QueryWrapper(),"transactdatetime"),
//    CFETS_RMB_CMDS_MARKET_DATAPSEND_RECORD(CfetsRmbCmdsMarketdataSendRecord.class, CfetsRmbCmdsMarketdataSendRecordDao.class),
    CFETS_RMB_CMDS_MSG_DOWN(CfetsRmbCmdsMsgDown.class, CfetsRmbCmdsMsgDownDao.class,new QueryWrapper(),"msgdate"),
    CFETS_RMB_CMDS_MSG_DOWN_HISTORY(CfetsRmbCmdsMsgDownHistory.class, CfetsRmbCmdsMsgDownHistoryDao.class,new QueryWrapper(),"msgdate"),
//    CFETS_RMB_CMDS_MSG_MSEND_RECORD(CfetsRmbCmdsMsgmSendRecord.class, CfetsRmbCmdsMsgmSendRecordDao.class),
    CFETS_RMB_TRADE_MSG_DOWN(CfetsRmbTradeMsgDown.class, CfetsRmbTradeMsgDownDao.class,new QueryWrapper(),"msgdate"),
    CFETS_RMB_TRADE_MSG_DOWN_HISTORY(CfetsRmbTradeMsgDownHistory.class, CfetsRmbTradeMsgDownHistoryDao.class,new QueryWrapper(),"msgdate"),
    CFETS_RMB_TRADE_MSG_UP(CfetsRmbTradeMsgUp.class, CfetsRmbTradeMsgUpDao.class,new QueryWrapper(),"msgdate"),
    CFETS_RMB_TRADE_MSG_UPHISTORY(CfetsRmbTradeMsgUpHistory.class, CfetsRmbTradeMsgUpHistoryDao.class,new QueryWrapper(),"msgdate"),
    ;

    private Class entityClass;

    private Class mapperClass;

    private QueryWrapper wrapper;

    private String column;

    public static void buildWrapper(String beginDate,String endDate){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        Date begin = null;
        Date end = null;
        try {
            if (StringUtils.isNotBlank(beginDate)){
                begin = simpleDateFormat.parse(beginDate);
            }
            if (StringUtils.isNotBlank(endDate)){
                end = simpleDateFormat.parse(endDate);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        for (DbEntityEnum dbEntityEnum : DbEntityEnum.values()) {
            QueryWrapper wrapper = dbEntityEnum.getWrapper();
            String column = dbEntityEnum.getColumn();
            if (begin!=null && end!=null){
                wrapper.between(column,begin,end);
                continue;
            }
            if (begin!=null && end==null){
                wrapper.ge(column,begin);
                continue;
            }
            if (begin==null && end!=null){
                wrapper.lt(column,end);
            }
        }
    }
}
